﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MacViet.DataBaseAPI;
using System.Data.SqlClient;

public partial class Control_Employees_WebUserControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        EMPLOYEESDataAPI api = new EMPLOYEESDataAPI();
        if (!IsPostBack)
        {
            grvShow.DataSource = api.getAll();
            //grvShow.DataBind();
        }
        
        
        //grvShow.DeleteRow = api.deleteByPrimaryKeys();
        //grvShow.DataBind();
    }
    protected void DeleteBtn_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < grvShow.Rows.Count; i++)
        {
            string id = string.Empty;
            GridViewRow rows=grvShow.Rows[i];
            bool chekBox = (rows.FindControl("chkSelect") as CheckBox).Checked;
            if (chekBox)
            {
                if (id == string.Empty)
                {
                    id = grvShow.DataKeys[i].Value.ToString();
                    EMPLOYEESDataAPI api = new EMPLOYEESDataAPI();
                    api.deleteByPrimaryKeys(int.Parse(id));
                    grvShow.DataSource = api.getAll();
                    grvShow.DataBind();
                }
                else
                    id += grvShow.DataKeys[i].Value.ToString() + ",";
            }
        }       

    }
    
}
